<?php
/**
  * CLOUD
  *
  * This is not a freeware, use is subject to license terms
  * @author CLOUD DEV TEAM
  * 
  */
if (!defined('IN_CLOUD')) exit('Access Denied!');

class Url
{
	/**
	 * 显示提示页面
	 * @param string $url
	 * @param string $msg
	 * @param bool $goBack
	 */
	public static function showMsg( $msg , $url = 'goBack' )
	{
		View::cleanTplCompile( 'showmsg.htm' );
		
		$viewModel = View::getInstance();
		$viewModel->tplAssign(
			array(
				'msg',
				'url',
			),
			array(
				$msg,
				$url,
			)
		);
		$viewModel->display( 'showmsg.htm' );
		exit;
	}
	
	/**
	 * 跳转
	 * @param string $url
	 */
	public static function redirectUrl( $url )
	{
		header( "Location: " . ( $url ? $url : SITEURL ) );
	}
	
	/**
	 * 伪静态
	 * @param string $m
	 * @param array $arr
	 */
	public static function rewriteUrl( $m , $arr = array() )
	{
		$url = '';
		$isUrlRewrite = Common::getConfig( 'System' , 'isUrlRewrite' );

		if ( $m == 'hireHouseIndex' )
		{
			if ( $isUrlRewrite )
			{
				$url .= SITEURL . '/hireHouse/';
				$url .= 'r' . ( int )$arr['regionId'] . '/' . 're' . ( int )$arr['rent'] . '/' . 'ro' . ( int )$arr['room'] . '/' . 'b' . ( int )$arr['broker'] . '/';
				if ( $arr['page_id'] )
					$url .= ( int )$arr['page_id'] . '/';
			}
			else
			{
				$url .= SITEURL . '?c=hireHouse';
				if ( $arr['regionId'] )
				{
					$url .= '&amp;region_id=' . ( int )$arr['regionId'];
				}
				if ( $arr['rent'] )
				{
					$url .= '&amp;rent=' . ( int )$arr['rent'];
				}
				if ( $arr['room'] )
				{
					$url .= '&amp;room=' . ( int )$arr['room'];
				}
				if ( $arr['broker'] )
				{
					$url .= '&amp;broker=' . ( int )$arr['broker'];
				}
				if ( $arr['page_id'] )
				{
					$url .= '&amp;page_Id' . ( int )$arr['page_id'];
				}
			}
		}
		elseif ( $m == 'hireHouseDetail' )
		{
			if ( $isUrlRewrite )
			{
				$url .= SITEURL . '/hireHouse/' . $arr['houseId'] . '.html';
			}
			else
			{
				$url .= SITEURL . '?c=hireHouse&a=detail&house_id=' . $arr['houseId'];
			}
		}
		elseif ( $m == 'sellHouseIndex' )
		{
			if ( $isUrlRewrite )
			{
				$url .= SITEURL . '/sellHouse/';
				$url .= 'r' . ( int )$arr['regionId'] . '/p' . ( int )$arr['price'] . '/a' . ( int )$arr['area'] . '/ro' . ( int )$arr['room'] . '/b' . ( int )$arr['broker'] . '/';
				if ( $arr['page_id'] )
					$url .= ( int )$arr['page_id'] . '/';
			}
			else
			{
				$url .= SITEURL . '?c=hireHouse';
				if ( $arr['regionId'] )
				{
					$url .= '&amp;region_id=' . ( int )$arr['regionId'];
				}
				if ( $arr['price'] )
				{
					$url .= '&amp;price=' . ( int )$arr['price'];
				}
				if ( $arr['area'] )
				{
					$url .= '&amp;area=' . ( int )$arr['area'];
				}
				if ( $arr['room'] )
				{
					$url .= '&amp;room=' . ( int )$arr['room'];
				}
				if ( $arr['broker'] )
				{
					$url .= '&amp;broker=' . ( int )$arr['broker'];
				}
				if ( $arr['page_id'] )
				{
					$url .= '&amp;page_Id' . ( int )$arr['page_id'];
				}
			}
		}
		elseif ( $m == 'sellHouseDetail' )
		{
			if ( $isUrlRewrite )
			{
				$url .= SITEURL . '/sellHouse/' . $arr['houseId'] . '.html';
			}
			else
			{
				$url .= SITEURL . '?c=sellHouse&a=detail&house_id=' . $arr['houseId'];
			}
		}
		return $url;
	}
}